package com.nut.lmsc.api.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.nut.lmsc.api.req.MemberQueryReq;
import com.nut.lmsc.common.Result;
import com.nut.lmsc.entity.Member;
import com.nut.lmsc.service.MemberService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.Set;

@Slf4j
@RestController
@RequestMapping("/admin/member")
public class MemberController {

    @Autowired
    private MemberService memberService;

    @GetMapping("/list")
    public Result<IPage<Member>> listPage(MemberQueryReq req) {
        return memberService.listPage(req);
    }

    @GetMapping(value = "/{id}")
    public Result<Member> detail(@PathVariable String id) {
        return memberService.getById(Long.valueOf(id));
    }

    @PostMapping
    public Result add(@RequestBody Member member) {
        return memberService.add(member);
    }

    @PutMapping
    public Result update(@RequestBody Member member) {
        return memberService.updateById(member);
    }

    @DeleteMapping
    public Result delete(@RequestBody Set<Serializable> ids) {
        return memberService.deleteByIds(ids);
    }
    
}
